<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: SlideShowPortlet.php 426 2011-01-05 10:36:10Z steen.rabol $
 *
 */

Prado::using('Application.Portlets.Portlet');
Prado::using('Application.Portlets.SlideShowPortlet.Common.SlideShowPortletRecord');

class SlideShowPortlet extends Portlet
{
	public function onLoad($p)
	{
		parent::onLoad($p);

		// Publish Js
		$assetManager	= $this->getApplication()->getAssetManager();
		$clientScripts	= $this->getPage()->getClientScript();

		$pubURL		= $assetManager->publishFilePath(Prado::getPathOfNamespace('Application.Portlets.SlideShowPortlet.Common.js'));

		// Register JS
		$clientScripts->registerScriptFile('slideshow',$pubURL . '/slideshow.js');

		// Build script
		$i			= 0;
		$id			= $this->Parameters['id'];
		$slscript	= "var ssimages_$id=new Array();\r\n";
		$shFiles	= SlideShowPortletRecord::finder()->findAllBypid($id);
		foreach($shFiles as $shFile)
		{
			$fileurl = $this->Application->PortalBaseUrl . 'storage/SlideShowPortlet/' . $id . '/' . $shFile->filename;
			$slscript .= "ssimages_" . $id . "[" . $i . "]=['" . $fileurl . "','',''];\r\n";
			$i++;
		}

		$clientScripts->registerHeadScript("slideshow_" . $id,$slscript);

		$cval		= Prado::unserialize($this->ConfigRecord->value);
		$borderwidth	= 0;
		$pause			= 0;
		$this->SlideShowJS->Text = "new fadeshow(ssimages_$id," . $cval['width'] ."," . $cval['height'] . ",$borderwidth," . (TPropertyValue::ensureInteger($cval['delay']) * 1000) . ",$pause);";
	}

	protected function getConfigName()
	{
		return get_class() . '_' . $this->Parameters['id'];
	}
}
?>